﻿using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Mt.Site.Core.Organizations.UserCache;
using Mt.Site.Core.WorkFlows.Enum;
using System;
using System.ComponentModel.DataAnnotations;

namespace Mt.Site.Core.WorkFlows.Design.Entities
{
    public class WorkFlowNode : FullAuditedEntity<Guid>, IMustHaveTenant, IPassivable
    {
        public const int MaxNameLength = 128;
        public const int MaxDescriptionLength = 512;
        public const int MaxShortNameLength = 50;
        public const int MaxUserIdListLength = 5000;
        public const int MaxActionListLength = 500;
        public const int MaxNextNodeListLength = 500;
        public const int MaxBackNodeListLength = 500;
        public const int MaxHandlingTimeLimitLength = 500;
        public const int MaxFilterStrLength = 2000;

        public const int MaxOptionFunctionLength = 300;
        public const int MaxCustomDataLength = 3000;

        public int TenantId { get; set; }

        /// <summary>
        /// 流程id
        /// </summary>
        public Guid WorkflowId { get; set; }

        public bool IsActive { get; set; }

        public int Order { get; set; }

        [StringLength(MaxNameLength)]
        [Required]
        public string Name { get; set; }

        [StringLength(MaxShortNameLength)]
        public string ShortName { get; set; }

        [StringLength(MaxDescriptionLength)]
        public string Description { get; set; }

        public ActionScheme ActionScheme { get; set; }


        /// <summary>
        /// 下一步的备选项，id序列（,号分割）
        /// </summary>
        [StringLength(MaxNextNodeListLength)]
        public string NextNodeList { get; set; }

        /// <summary>
        /// 后退的备选项，id序列（,号分割）
        /// </summary>
        [StringLength(MaxBackNodeListLength)]
        public string BackNodeList { get; set; }

        /// <summary>
        /// 特殊指定当前节点的可选经办人（,号分割） ，不选则默认为所有可参与本流程的人员
        /// </summary>
        [StringLength(MaxUserIdListLength)]
        public string UserIdList { get; set; }

        /// <summary>
        /// IAction.UniqueName（,号分割）
        /// </summary>
        [StringLength(MaxActionListLength)]
        public string ActionList { get; set; }

        /// <summary>
        /// 是否可以编辑附件
        /// </summary>
        public bool CanEditAttachment { get; set; }

        /// <summary>
        /// (待选人员的过滤)按用户级别，经办人等自定义过滤
        /// </summary>
        public OperatorFilter BeforeSelectFilter { get; set; }

        /// <summary>
        /// (待选人员的过滤)补充过滤，按用户职务
        /// </summary>
        [StringLength(MaxFilterStrLength)]
        public string BeforeSelectMoreFilter { get; set; }

        /// <summary>
        ///  (自动匹配默认的选中人员)按用户级别，经办人等自定义过滤
        /// </summary>
        public OperatorFilter SelectedFilter { get; set; }

        /// <summary>
        ///   (自动匹配默认的选中人员)  补充过滤，按用户职务
        /// </summary>
        [StringLength(MaxFilterStrLength)]
        public string SelectedMoreFilter { get; set; }

        /// <summary>
        /// 默认的时间期限（以天为单位吧）
        /// </summary>
        [StringLength(MaxHandlingTimeLimitLength)]
        public string HandlingTimeLimit { get; set; }

        /// <summary>
        /// 在可确定下一步的节点和人员后，是否自动发送
        /// </summary>
        public bool IsAutoSendToNext { get; set; }

        [StringLength(MaxOptionFunctionLength)]
        public string OptionFunction { get; set; }

        [StringLength(MaxCustomDataLength)]
        public string CustomData { get; set; }
    }
}
